IF OBJECT_ID('ssf.ddl_drop_table') IS NOT NULL
	DROP PROCEDURE ssf.ddl_drop_table
GO

CREATE PROCEDURE ssf.ddl_drop_table
	@table_name NVARCHAR(512)
AS
/*

*/

SET NOCOUNT ON

-- ============
/*<code_comment><![CDATA[declare dynamic sql variables]]></code_comment>*/
DECLARE	@sql_error INT
			, @row_count BIGINT
			, @sql VARCHAR(MAX)
			, @nsql NVARCHAR(MAX)
			, @crlf CHAR(2) = CHAR(13) + CHAR(10)
			, @quote CHAR(1) = CHAR(39)
			, @two_quotes CHAR(2) = CHAR(39) + CHAR(39)
			, @tab CHAR(1) = CHAR(9)
-- ============

-- ============
/*<code_comment><![CDATA[declare local variables]]></code_comment>*/
DECLARE	@exists_fl BIT = NULL
-- ============

-- ============
/*<code_comment><![CDATA[test table existence]]></code_comment>*/
EXECUTE @sql_error = ssf.ddl_exists_table
	@table_name = @table_name
	-- NVARCHAR(512)
	, @exists_fl = @exists_fl OUTPUT
	-- BIT OUTPUT

IF ISNULL(@sql_error, 1) <> 0
OR @exists_fl IS NULL
BEGIN
	RAISERROR('Failed to test table existence: <%s>.', 16, 1, @table_name)
	RETURN 1
END
-- ============

-- ============
/*<code_comment><![CDATA[return unless the table exists]]></code_comment>*/
IF @exists_fl = 0
	RETURN @@ERROR
-- ============

-- ============
/*<code_comment><![CDATA[drop the table]]></code_comment>*/
SET @nsql = 'DROP TABLE ' + @table_name

PRINT @nsql

EXECUTE(@nsql)

SET @sql_error = @@ERROR

IF ISNULL(@sql_error, 1) <> 0
BEGIN
	RAISERROR('Dynamic sql failed: %s.', 16, 1, @nsql)
	RETURN @sql_error
END
-- ============

RETURN @@ERROR
GO
